Skip to content

fix(bridge): preserve NVIDIA Build token usage - #578

Merged
chrisknvidia merged 5 commits into
mainfrom
fix/christopherk/bridge-token-usage
Nov 15, 2026
Merged

chrisknvidia merged 5 commits into
mainfrom
fix/christopherk/bridge-token-usage

Conversation

@chrisknvidia

@chrisknvidia chrisknvidia commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When Codex or Claude Code ran through the NVIDIA Build bridge, Tier 3 recorded no token usage even though every bridged request succeeded: Codex usage was null and Claude Code usage was 0. The bridge dropped the upstream chat-completion usage. Responses API replies set "usage": None, and Anthropic Messages events hardcoded input_tokens: 0, output_tokens: 0.

The bridge now maps reported prompt, completion and cached tokens into each API's own usage shape:

  • Responses response.completed: input_tokens, output_tokens, input_tokens_details.cached_tokens.
  • Anthropic message_start / message_delta: input_tokens excluding cache reads, cache_read_input_tokens, output_tokens.

Responses usage stays null when upstream reports none. Anthropic usage is always schema-valid: missing input_tokens/output_tokens default to 0, and uncached input is clamped at 0. The bridge also returns a plain JSON Messages reply when a client asks for non-streaming output.

Real Docker run after the change (one case, --skip-baseline), from result.json token_usage.agents.<agent>.with_skill.totals:

Agent prompt cached completion total
codex 77,877 69,376 933 78,810
claude-code 35,774 21,680 858 36,632

Before the change, the same configuration recorded null (codex) and 0 (claude-code).

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests (tests/test_nvidia_build_bridge.py: measured, missing, completion-only, invalid and cache-exceeds-prompt usage, with strict Anthropic SDK validation of streaming and non-streaming replies)
  • Updated documentation for user-visible changes
  • Ran ruff check / ruff format --check on changed files
  • Ran pytest tests/test_nvidia_build_bridge.py (145 passed)
  • Ran make build
  • Did not add credentials, private datasets, or proprietary benchmark content

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Devin Review

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
@chrisknvidia
chrisknvidia merged commit 22509d2 into main Nov 15, 2026
27 checks passed
@chrisknvidia
chrisknvidia deleted the fix/christopherk/bridge-token-usage branch November 15, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant